home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / Library / Grant's CGI Framework / Grant's CGI Framework / grantscgi / Interface / DialogFunc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-20  |  2.7 KB  |  120 lines

  1. /*****
  2.  *
  3.  *    DialogFunc.c
  4.  *
  5.  *    This is a support file for "Grant's CGI Framework".
  6.  *    Please see the license agreement that accompanies the distribution package
  7.  *    for licensing details.
  8.  *
  9.  *    Copyright ©1995,1996 by Grant Neufeld
  10.  *    grant@acm.com
  11.  *    http://arpp.carleton.ca/cgi/framework/
  12.  *
  13.  *****/
  14.  
  15. #include "MyConfiguration.h"
  16. #if kCompileWithForeground
  17.  
  18. #include <Threads.h>
  19.  
  20. #include "constants.h"
  21. #include "globals.h"
  22.  
  23. #include "Events.h"
  24. #include "WindowInt.h"
  25.  
  26. #include "DialogFunc.h"
  27.  
  28.  
  29. /***  LOCAL CONSTANTS ***/
  30.  
  31. #define kButtonFrameInset    -4
  32. #define kButtonFrameSize    3
  33.  
  34.  
  35. /***  FUNCTIONS  ***/
  36.  
  37. /* draw the button outline for the specified item */
  38. pascal void
  39. DialogDefaultButtonOutline ( DialogPtr theDialog, short itemNumber )
  40. {
  41. //    #pragma unused(itemNumber)
  42.     
  43.     PenState    curPen;
  44.     short        itemType;
  45.     Handle        itemHandle;
  46.     Rect        itemRect;
  47.     short        rectCornerRadius;
  48.     
  49.     GetPenState ( &curPen );
  50.     PenNormal ();
  51.     
  52. //    InsetRect ( &itemRect, kButtonFrameInset, kButtonFrameInset );
  53. //    FrameRoundRect ( &itemRect, 16, 16 );
  54.     
  55.     GetDialogItem ( theDialog, kDefaultButtonID, &itemType, &itemHandle, &itemRect );
  56.     if ( (itemHandle != NULL) &&
  57.         ((*(ControlHandle)itemHandle)->contrlHilite != nil) )
  58.     {
  59.         /* control is dimmed - draw in gray */
  60.         PenPat ( &qd.gray );
  61.     }
  62.     else
  63.     {
  64.         PenPat ( &qd.black );
  65.     }
  66.     
  67.     GetDialogItem ( theDialog, itemNumber, &itemType, &itemHandle, &itemRect );
  68.     PenSize ( kButtonFrameSize, kButtonFrameSize );
  69.     rectCornerRadius = ((itemRect.bottom - itemRect.top) / 2) + 2;
  70.     FrameRoundRect    ( &itemRect, rectCornerRadius, rectCornerRadius );
  71.     
  72.     SetPenState ( &curPen );
  73. } /* DialogDefaultButtonOutline */
  74.  
  75.  
  76.  
  77.  
  78. /* This function responds to update, and activate events, and key presses.
  79.     return, enter, Command-. and esc select the 'OK' button (kDefaultButtonID).
  80.     (There's no Cancel button) */
  81. pascal Boolean
  82. defaultAlert1ButtonEventFilter ( DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
  83. {
  84.     Boolean        result;
  85.     char        key;
  86.     short        itemType;
  87.     Handle        itemHandle;
  88.     Rect        itemRect;
  89.     long        finalTicks;
  90.     
  91.     result = false;
  92.     
  93.     switch ( theEvent->what )
  94.     {
  95.         case keyDown :
  96.             key = (char)( theEvent->message & charCodeMask );
  97.             
  98.             if ( (key == (char)kReturnKey) || (key == (char)kEnterKey) ||
  99.                 (key == (char)kEscapeKey) ||
  100.                 ((key == (char)kPeriodKey) && (theEvent->modifiers & cmdKey)) )
  101.             {
  102.                 GetDialogItem    ( theDialog, kDefaultButtonID, &itemType, &itemHandle, &itemRect );
  103.                 HiliteControl    ( (ControlHandle)itemHandle, 0 );
  104.                 Delay            ( (long)kVisualDelay, &finalTicks );
  105.                 HiliteControl    ( (ControlHandle)itemHandle, 0 );
  106.                 
  107.                 result   = true;
  108.                 *itemHit = (short)kDefaultButtonID;
  109.             }
  110.             break;
  111.     }
  112.     
  113.     return result;
  114. } /* defaultAlert1ButtonEventFilter */
  115.  
  116.  
  117. #endif    /* kCompileWithForeground */
  118.  
  119. /*****  EOF  *****/
  120.